#include "settingdialog.h"
#include "ui_settingdialog.h"

SettingDialog::SettingDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::SettingDialog)
{
    ui->setupUi(this);

    //QString defaultIP = "172.31.222.71";
    //int defaultPort = 59946;
    //emit changeIpPortNumber(defaultIP, defaultPort);


    ui->ipEdit1->setValidator(new QIntValidator(0,255, this));
    ui->ipEdit2->setValidator(new QIntValidator(0,255, this));
    ui->ipEdit3->setValidator(new QIntValidator(0,255, this));
    ui->ipEdit4->setValidator(new QIntValidator(0,255, this));
    ui->portEdit->setValidator(new QIntValidator(1,65535, this));

}

SettingDialog::~SettingDialog()
{
    delete ui;
}

void SettingDialog::on_saveButton_clicked()
{
    QString ip = ui->ipEdit1->text();
    ip.append(".");
    ip.append(ui->ipEdit2->text());
    ip.append(".");
    ip.append(ui->ipEdit3->text());
    ip.append(".");
    ip.append(ui->ipEdit4->text());

    int portNum = ui->portEdit->text().toInt();
    qDebug() << "port number: " << portNum;
    qDebug() << "ip address: " << ip;
    emit changeIpPortNumber(ip, portNum);
    this->close();
}

QString SettingDialog::getIpAddress()
{
    QString ip = ui->ipEdit1->text();
    ip.append(".");
    ip.append(ui->ipEdit2->text());
    ip.append(".");
    ip.append(ui->ipEdit3->text());
    ip.append(".");
    ip.append(ui->ipEdit4->text());
    return ip;
}

int SettingDialog::getPortNumber()
{
    //ui->portEdit->text().toInt();
    //return;
    return 0;
}

void SettingDialog::setIpAddress(QString ip)
{
    //QStringList ips = packet.split('.',QString::SkipEmptyParts);

}

void SettingDialog::setPortNumber(int)
{
}
